package cn.jinjimi.app.reader.holder;

import android.content.Context;
import android.graphics.PointF;
import android.view.View;

import com.baiiu.filter.util.UIUtil;
import cn.jinjimi.app.R;
import cn.jinjimi.app.reader.bean.JinjuViewData;
import cn.jinjimi.app.main.widget.CommonRV.BaseHolder;
import cn.jinjimi.app.main.widget.CommonRV.IActionListener;
import cn.jinjimi.app.main.widget.FrescoImageView.FrescoImageView;

/**
 * Created by lforxeverc on 2017/4/14.
 */

public class JinjuHolder extends BaseHolder<JinjuViewData> {
    private FrescoImageView ivJinju;
    private View pointStart, pointEnd;
    private int dp5, dp15;

    public JinjuHolder(View v, Context context, int type) {
        super(v, context, type);
        dp5 = UIUtil.dp(context, 5);
        dp15 = UIUtil.dp(context, 15);
    }

    @Override
    protected void initView() {
        ivJinju = (FrescoImageView) itemView.findViewById(R.id.iv_jinju);
        pointStart = itemView.findViewById(R.id.v_point_start);
        pointEnd = itemView.findViewById(R.id.v_point_end);
    }

    @Override
    public void setViews(final int position, final JinjuViewData data, final IActionListener mListener) {
        ivJinju.getHierarchy().setActualImageFocusPoint(new PointF(0.5f, 0f));
        ivJinju.loadView(data.getCoverUrl());

        boolean isRight = data.isRightItem();
        pointStart.getLayoutParams().width = isRight ? dp5 : dp15;
        pointEnd.getLayoutParams().width = (isRight ? dp15 : dp5);
    }

}
